<template>
	<view>
		<view class="msg_box" v-if="data !== undefined && data!== null && data .length>0">
			<view class="msg" v-for="(item,index) in data" :key="index" @click="details(item.id)">
				<text class="msg_time">{{item.sendTime}}</text>
				<view class="" style="display: flex;align-items: center;justify-content: space-between;">
					<text>{{item.title}}</text>
					<u-icon name="arrow-right" color="#b1b1b1" size="12"></u-icon>
				</view>
				<view class="msg_image">
					<image :src="item.images" :alt="item.title" />
				</view>
			</view>
		</view>
		<u-empty v-else mode="message" icon="/static/Empty/data_null.png" text="暂无消息">
		</u-empty>
	</view>
</template>

<script>
	var util = require('@/util/request5.js');
	export default {
		data() {
			return {
				data: [],
				display: false,
				bottom: true,
				page: 1,
			}
		},
		onLoad() {
			this._list()
		},
		//下拉刷新
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this._list()
			}
		},
		methods: {
			//跳转详情
			details(id) {
				uni.navigateTo({
					url: '/pages/merchant/msgDetail?id=' + id
				})
			},
			//列表接口
			async _list() {
				uni.showLoading({
					title: '加载中'
				});
				const merinfo = uni.getStorageSync('merinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Message/lists',
					data: {
						page: this.page
					},
					header: {
						'token': merinfo.token
					}
				});
				uni.hideLoading();
				if (res.code == 1) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length > 0) {
						res.data.data.map(item => {
							item.images = util.API_URL + item.images
						})
						if (this.page == 1) {
							this.data = res.data.data
						} else {
							this.data = [...this.data, ...res.data.data]
						}
						this.display = true
					} else {
						this.bottom = false
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}
	.msg_box {
		padding: 30rpx;
		box-sizing: border-box;

		.msg {
			// border-bottom: #eeeeee 1px solid;
			box-shadow: 0px 0px 30px -22px #888888;
			margin-bottom: 30rpx;
			border-radius: 15rpx;
			padding: 30rpx;
			background-color: #ffffff;

			.msg_time {
				// text-align: center;
				font-size: 24rpx;
				color: #666666;
				display: block;
				// margin: 30rpx 0 20rpx 0;
				padding-bottom: 20rpx;
				// border-bottom: 1px #eee dashed;
			}
			
			.msg_image {
				padding-top: 20rpx;
				image {
					width: 100%;
					border-radius: 12rpx;
				}
			}
		}

	}
</style>
